package com.gree.ssm.service.impl;

import com.gree.ssm.bean.Blog;
import com.gree.ssm.dao.BlogDao;
import com.gree.ssm.service.BlogService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Author :xiaossong
 * @Description: 博客实现类
 * @Date Created in 下午11:31 2017/10/18
 */
@Service("blogService")
public class BlogServiceImpl implements BlogService{

    @Resource
    private BlogDao blogDao;

    public List<Blog> countList() {
        return blogDao.countList();
    }

    public List<Blog> list(Map<String, Object> map) {

        List<Blog> blogs = blogDao.list(map);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        List<Blog> newBlogs = new ArrayList<Blog>();
        for(Blog blog : blogs){
            blog.setReleaseDateStr(sdf.format(blog.getReleaseDate()));
            newBlogs.add(blog);
        }
        return newBlogs;
    }

    public Long getTotal(Map<String, Object> map) {
        return blogDao.getTotal(map);
    }

    public Blog findById(Integer id) {
        return blogDao.findById(id);
    }

    public Integer update(Blog blog) {
        return blogDao.update(blog);
    }

    public Blog getLastBlog(Integer id) {
        return blogDao.getLastBlog(id);
    }

    public Blog getNextBlog(Integer id) {
        return blogDao.getNextBlog(id);
    }

    public Integer add(Blog blog) {
        return blogDao.add(blog);
    }


    public Integer delete(Integer id) {
        return blogDao.delete(id);
    }



}